

* DECOMPOSE COIBION ET AL ESTIMATE INTO SOURCES OF IDENTIFYING VARIATION 
* VISUAL DESCRIPTION OF CGR FLAW


* ************* GENERATE FIG I1 *******************
quietly{
use WorkingData, clear

* trimmed weighted (figure in qje submission)

drop if trims==1
collapse (mean) it12all infl [aw=peso], by(dp treatment_old)

* CGR use 2012:3 - 2019:1

drop if dp>=yq(2019,2)

* this is CGR explanatory variable: (inflation rate presented to treated firms)*(dumy for information status= 1 if informed, 0 otherwise)
gen CGR_Treat=infl*treat

gen n=2
expand n
sort dp treat
by  dp treat: gen t=_n-1
lab def lt 0 "CGR treatment" 1 "Actual relationship"
lab val t lt

#delimit;
scatter it12all  CGR_Treat if treat==1&t==0, yaxis(1 2) msy(o) mco(black)||
scatter it12all  CGR_Treat if treat==0&t==0, msy(sh) mco(black)||
scatter it12all  infl    if treat==1&t==1, msy(o) mco(black)||
scatter it12all  infl    if treat==0&t==1, msy(sh) mco(black) 
legend(order(1 2) lab(1 "Informed") lab(2 "Not informed") region(c(none))) xti("Most recent inflation data at survey time") yti("Expected one-year inflation") 
yla(-1(1)4,angle(0) grid) yla(-1(1)4,angle(0) grid axis(2)) xla(-1(1)4,angle(0) grid) yscale(range(-1.2 4.2))  yscale(range(-1.2 4.2) axis(2) ) xscale(range(-1.2 4.2)) 
xsize(20) ysize(13) by(t, row(1) graphregion(c(white))  note("") legend(pos(6)) ) subti(, bc(white)) ;
graph export FigCGR_I1.eps, replace;
#delimit cr
}
* ============================
* PRINT TO LOG DATA FOR FIG I1
sort t treat dp
* ***************************
* ***** DATA FOR FIG I1 *****
* ***************************
list dp t treat infl CGR_Treat, linesize(255) header noobs


* ***************** GENERATE TABLE I1 *********************************
* BREAKDOWN BETA ESTIMATED BY CGR INTO SOURCES OF IDENTIFYING VARIATION

*** CGR full sample 2012:3-2019:1
quietly{
use WorkingData, clear

* NOTE: TABLE I1 IN SUBMISSION AND WP WAS BASED ON INFLATION DATA USED IN CGR ESTIMATION WHICH HAS A FEW IMPUTATION MISTAKES
* I NOW REPORT SAME CALCULATIONS WITH CORRECT INFLATION DATA PRESENTED TO FIRMS

keep if dp>=yq(2012,3) & dp<=yq(2019,1) 

regr it12all Treat [aw=peso]
local beta=_b[Treat]

keep if e(sample)

corre it12all infl [aw=peso] if treat==1, cov
local cov_e_p_1 = r(cov_12)

qui sum it12all [aw=peso] if treat==1, d
local var_e_1=r(Var)
local mean_e_1=r(mean)

qui sum infl    [aw=peso] if treat==1, d
local var_p_1=r(Var)
local mean_p_1=r(mean)

qui sum it12all [aw=peso] if treat==0, d
local var_e_0=r(Var)
local mean_e_0=r(mean)

qui sum Treat [aw=peso], d
local var_Treat=r(Var)
local mean_Treat=r(var)

qui sum treatment [aw=peso]
local P_1=r(mean)

regr it12all Treat [aw=peso] if treat==1
local betat=_b[Treat]
di $_betat

local decobeta0= ($_cov_e_p_1 / $_var_p_1)*( ($_P_1 * $_var_p_1)/$_var_Treat ) + (($_mean_e_1 - $_mean_e_0)/$_mean_p_1 )*(1 - ($_P_1 * $_var_p_1)/$_var_Treat )
local decobeta1= $_betat*( ($_P_1 * $_var_p_1)/$_var_Treat ) + (($_mean_e_1 - $_mean_e_0)/$_mean_p_1 )*(1 - ($_P_1 * $_var_p_1)/$_var_Treat )


di 2*abs($_decobeta1 - $_beta)/abs($_decobeta + $_beta)


mat def CMP=J(11,6,.)
cap drop G
egen G=group(setton5 trimestre)
qui areg it12all  Treat [aw=peso], a(G)
local betacgr=_b[Treat]

mat CMP[ 1,3]=$_betacgr
mat CMP[ 2,3]=$_beta
mat CMP[ 3,2]=$_betat
mat CMP[ 4,2]=$_mean_e_1 - $_mean_e_0
mat CMP[ 5,2]=$_mean_p_1 
mat CMP[ 6,3]=($_mean_e_1 - $_mean_e_0)/$_mean_p_1 
mat CMP[ 7,2]=$_var_p_1
mat CMP[ 8,2]=$_var_Treat
mat CMP[ 9,2]=$_P_1
mat CMP[10,3]=($_P_1 * $_var_p_1)/$_var_Treat 
mat CMP[11,3]=$_decobeta1

}

*** CGR ELB 2014:1 - 2019:1

quietly{
keep if dp>=yq(2014,1) & dp<=yq(2019,1)

regr it12all Treat [aw=peso]
local beta=_b[Treat]
di $_beta

keep if e(sample)

corre it12all infl [aw=peso] if treat==1, cov
local cov_e_p_1 = r(cov_12)

qui sum it12all [aw=peso] if treat==1, d
local var_e_1=r(Var)
local mean_e_1=r(mean)

qui sum infl    [aw=peso] if treat==1, d
local var_p_1=r(Var)
local mean_p_1=r(mean)

qui sum it12all [aw=peso] if treat==0, d
local var_e_0=r(Var)
local mean_e_0=r(mean)

qui sum Treat [aw=peso], d
local var_Treat=r(Var)
local mean_Treat=r(var)

qui sum treatment [aw=peso]
local P_1=r(mean)

regr it12all Treat [aw=peso] if treat==1
local betat=_b[Treat]
di $_betat

local decobeta= ($_cov_e_p_1 / $_var_p_1)*( ($_P_1 * $_var_p_1)/$_var_Treat ) + (($_mean_e_1 - $_mean_e_0)/$_mean_p_1 )*(1 - ($_P_1 * $_var_p_1)/$_var_Treat )
local decobeta1= $_betat*( ($_P_1 * $_var_p_1)/$_var_Treat ) + (($_mean_e_1 - $_mean_e_0)/$_mean_p_1 )*(1 - ($_P_1 * $_var_p_1)/$_var_Treat )

di 2*abs($_decobeta1 - $_beta)/abs($_decobeta + $_beta)
cap drop G
egen G=group(setton5 trimestre)
qui areg it12all  Treat [aw=peso], a(G)
local betacgr=_b[Treat]

mat CMP[ 1,6]=$_betacgr
mat CMP[ 2,6]=$_beta
mat CMP[ 3,5]=$_betat
mat CMP[ 4,5]=$_mean_e_1 - $_mean_e_0
mat CMP[ 5,5]=$_mean_p_1 
mat CMP[ 6,6]=($_mean_e_1 - $_mean_e_0)/$_mean_p_1 
mat CMP[ 7,5]=$_var_p_1
mat CMP[ 8,5]=$_var_Treat
mat CMP[ 9,5]=$_P_1
mat CMP[10,6]=($_P_1 * $_var_p_1)/$_var_Treat 
mat CMP[11,6]=$_decobeta1
}

drop _all
svmat CMP
	format CMP* %6.3f
	outsheet CMP* using tableCGRbreakdown, delim("&") replace

* ============================================
* PRINT TO LOG TABLE I1
rename CMP2 AllSample_col1
rename CMP3 AllSample_col2
rename CMP5 ELBSample_col1
rename CMP6 ELBSample_col2
drop CMP1
gen RowItems=""
replace RowItems = "Theta_CGR" if _n==1
replace RowItems = "Theta_NoSectXSeas dummies" if _n==2
replace RowItems = "Theta_T" if _n==3
replace RowItems = "Delta_F" if _n==4
replace RowItems = "Pi_star" if _n==5
replace RowItems = "Delta_F/Pi_star" if _n==6
replace RowItems = "Var(T|I=1)" if _n==7
replace RowItems = "Var(T)" if _n==8
replace RowItems = "Prob(I=1)" if _n==9
replace RowItems = "Sigma_T" if _n==10
replace RowItems = "Theta_TSigma_T+(Delta_F/Pi_star)(1-Sigma_T)" if _n==11
list RowItems AllSample_col1 AllSample_col2 ELBSample_col1 ELBSample_col2, linesize(255) header noobs
